package com.geeksaga.service;

import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataAccessException;
import org.springframework.stereotype.Service;

import com.geeksaga.dao.ProjectMemberDao;
import com.geeksaga.domain.Project;
import com.geeksaga.domain.ProjectMember;
import com.geeksaga.domain.Spec;

/**
 * @author newbie
 * @since 0.1
 */
@Service
public class ProjectMemberServiceImpl implements ProjectMemberService {

    protected static final Log logger = LogFactory.getLog(ProjectMemberServiceImpl.class);
    
    @Autowired private ProjectMemberDao projectMemberDao;
    
    /* (non-Javadoc)
     * @see com.geeksaga.service.ProjectMemberService#add(com.geeksaga.domain.ProjectMember)
     */
    public ProjectMember add(ProjectMember member) throws DataAccessException {
        return projectMemberDao.add(member);
    }

    /* (non-Javadoc)
     * @see com.geeksaga.service.ProjectMemberService#findByProject(com.geeksaga.domain.Project)
     */
    public List<ProjectMember> findListByProject(Project project) throws DataAccessException {
        return projectMemberDao.findListByProject(project);
    }
    
    /* (non-Javadoc)
     * @see com.geeksaga.service.ProjectMemberService#isManager(com.geeksaga.domain.Spec, com.geeksaga.domain.Project)
     */
    public boolean isManager(Spec spec, Project project) throws DataAccessException {
        Map<String, String> manager = projectMemberDao.findByProject(project);
        String projectCode = manager.get(spec.getUserSid());
        
        if(project != null && project.getProjectCode().equals(projectCode))
            return true;
        
        return false;
    }
}